ANDROID_JAR=/usr/lib/android-sdk/platforms/android-23/android.jar
DX=/usr/lib/android-sdk/build-tools/debian/dx
AAPT=/usr/lib/android-sdk/build-tools/debian/aapt
APPDOMAIN=org/cakejs2
APPNAME=CakeJS2

.PHONY : build
.PHONY : deploy
.PHONY : clean

all: build

build : ./bin/$(APPNAME).apk

./bin/$(APPNAME).apk: ./bin/$(APPNAME)-unsigned.apk
	./sign.sh $< $@

./bin/$(APPNAME)-unsigned.apk: ./bin/classes.dex
	$(AAPT) package -v -f -A ./assets -M ./AndroidManifest.xml -S ./res -I ${ANDROID_JAR} -F $@ ./bin

./bin/classes.dex: ./obj/$(APPDOMAIN)/MainActivity.class
	$(DX) --dex --verbose --output $@ ./obj

./src/$(APPDOMAIN)/R.java : $(shell find ./res -type f)
	$(AAPT) package -v -A ./assets -f -m -S ./res -J ./src -M ./AndroidManifest.xml -I ${ANDROID_JAR}

./obj/$(APPDOMAIN)/MainActivity.class: src/$(APPDOMAIN)/MainActivity.java src/$(APPDOMAIN)/R.java
	javac -source 1.7 -target 1.7 -d ./obj \
	-bootclasspath ${ANDROID_JAR} -classpath ${ANDROID_JAR} \
	-sourcepath ./src $<

install: ./bin/$(APPNAME).apk
	adb install ./bin/$(APPNAME).apk

clean:
	rm -fr ./bin/* ./obj/* ./src/$(APPDOMAIN)/R.java
